package uy.edu.um.ltic.server.business;

import java.sql.Timestamp;
import java.util.ArrayList;

import uy.edu.um.ltic.exception.DataBaseException;
import uy.edu.um.ltic.server.persistence.MessageDAOFactory;

public class MessageMgr implements MessageMgt{
	private static MessageMgr instance;
	

	private MessageMgr() {
	}

	public static MessageMgr getInstance() {
		if (instance == null) {
			instance = new MessageMgr();
		}
		return instance;
	}

	@Override
	public void addMessage(Message oMessage) throws DataBaseException {
			MessageDAOFactory.getInstance().getMessageDAOMgt().addMessage(oMessage);
	}

	
	@Override
	public ArrayList<Message> getMessagesBetweenTwo(Employee windowBeingShown,
			Employee anotherOne) throws DataBaseException {
		Employee oReci = new Employee(anotherOne.getnEmployee());
		Employee oSender = new Employee(windowBeingShown.getnEmployee());
		ArrayList<Message> oList = MessageDAOFactory.getInstance()
				.getMessageDAOMgt().getMessagesBetweenTwo(oSender, oReci);
		
		return oList;
	}

	@Override
	public ArrayList<ConferenceMessage> getConferenceMessages(int idConference) throws DataBaseException {
		return  MessageDAOFactory.getInstance()
				.getMessageDAOMgt().getConferenceMessages(idConference);
	}

	@Override
	public ArrayList<Employee> getLastEmployees(int nEmployee) throws DataBaseException {
			return  MessageDAOFactory.getInstance()
				.getMessageDAOMgt().getLastEmployees(nEmployee);
	}

	@Override
	public ArrayList<TextMessage> getMessagesWithTheWord(String word) throws DataBaseException {
		return MessageDAOFactory.getInstance().getMessageDAOMgt().getMessagesWithTheWord(word);
	}

	@Override
	public int getAmountOfWordsWritten(int nEmployee, Timestamp date1,
			Timestamp date2) throws DataBaseException {
		return MessageDAOFactory.getInstance().getMessageDAOMgt().getAmountOfWordsWritten(nEmployee, date1, date2);
	}

	@Override
	public ArrayList<Integer> getFilesFromOneEmployeeToAnother(int sender,
			int receiver) throws DataBaseException {
		return MessageDAOFactory.getInstance().getMessageDAOMgt().getFilesFromOneEmployeeToAnother(sender, receiver);
	}

	@Override
	public String getNameOfFile(int id) throws DataBaseException {
		return MessageDAOFactory.getInstance().getMessageDAOMgt().getNameOfFile(id);
	}

	@Override
	public byte[] getFile(int id) throws DataBaseException {
		return MessageDAOFactory.getInstance().getMessageDAOMgt().getFile(id);
	}

}
